﻿<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link th:href="@{/hplus/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/hplus/css/animate.min.css}" rel="stylesheet">
    <link th:href="@{/hplus/css/style.min.css}" rel="stylesheet">
    <link th:href="@{/Xadmin/lib/layui/css/layui.css}" rel="stylesheet"/>
    <script th:src="@{/Xadmin/lib/layui/layui.js}"></script>
    <script th:src="@{/Scripts/jquery-3.4.1.min.js}"></script>
    <script th:src="@{/Xadmin/js/xadmin.js}"></script>
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" name="searContent" id="crReload" placeholder="请输入原料名" autocomplete="off">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" id="btncrReload" onclick="SelectName()" data-type="reload">搜索</button>
                            </div>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('添加','/BasicData/InsertRawMaterial',470,400)"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-hide" id="layuiTable" lay-filter="layuiTable"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script type="text/html" id="barContract">
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
        <script>
        //根据名字搜索
        function SelectName() {
            layui.table.reload('layuiTable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    name: $("#crReload").val()
                }
            });
        }
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#layuiTable'
                , url:'/api/RawHouse/get'
                , limit:15
                , limits: [15, 25, 35]
                ,title: '用户数据表'
                , cols: [
                    [
                        {field: 'id', title: '商品名', fixed: 'left', unresize: true}
                        , {field: 'kindid', title: '商品名', fixed: 'left', unresize: true}
                        , {field: 'name', title: '数量', sort: true}
                        , {field: 'primeCost', title: '成本', sort: true}
                        , {field: 'unit', title: '单位', sort: true}
                        , { fixed: 'right', title: '操作', width: 180, toolbar: '#barContract' }
                ]
                ]
                , page: true
            });
          
            //监听行工具事件
            table.on('tool(layuiTable)', function(obj){
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么',
                        function (index) {
                            console.log(data)
                            $.ajax({
                                url: `/api/RawHouse/delete?id=${data.id}`,
                                type: 'DELETE',
                                success: function (res) {
                                    if (res.code === 0) {
                                        layer.msg(res.msg);
                                        obj.del();
                                        layer.close(index);
                                    } else {
                                        layer.msg(res.msg);
                                    }
                                }
                            });
                        });
                } else if (obj.event === 'edit') {

                    layer.open({
                        type: 2,
                        title: '编辑',
                        fixed: false, //不固定
                        maxmin: true,
                        content: '/BasicData/UpdateRawMaterial',
                        area: ['70%', '95%'],
                        success: function (layero, index) {
                            var iframe = window['layui-layer-iframe' + index];
                            //调用子页面的全局函数
                            iframe.child(data.id);
                        }
                    });
                }
            });
        });
        </script>
    </div>
</body>
</html>
